<template>
	<view class="mainCss">
		<van-search use-action-slot shape="round" placeholder="请输入搜索关键词"></van-search>
		<view class="sw">
			<view class="uni-margin-wrap">
				<swiper class="swiper" :easing-function="linear" circular :indicator-dots="true" :autoplay="true"
					:interval="3000" :duration="750">
					<swiper-item v-for="item in imgArr" :key="item.id">
						<view class="swiper-item">
							<image class="imgs" :src="'http://localhost:8848/' + item.icon" mode="aspectFill"></image>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<!-- <Swiper></Swiper> -->
		<!-- 轮播商品 -->

		<view class="fenlei">
			<van-cell title="分类" is-link @click="showPopup" />
			<van-popup :show="show" round position="bottom" custom-style="height: 35%" @close="onClose">
				<van-picker :columns="columns" :show-toolbar="true" title="品牌商" @confirm="onConfirm"
					@cancel="onCancel" />
			</van-popup>

		</view>
		<!-- <GoodsGrid :imgArr="imgArr"></GoodsGrid> -->
		<!-- 展示商品 -->
		<view class="all">
			<view class="goods">
				<view class="title" v-for="item in fzdArr" :key="item.id">
					<image class="img" :src="'http://localhost:8858/' + item.goodsicon" mode="scaleToFill"
						@click="gotoDetali(item.id,item.goodsname,item.goodsicon)">
					</image>
					<view class="Goodsjg">
						<!-- ￥{{item.goodsprice}} -->
					</view>
					<view class="GoodsText">
						{{item.goodsname}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				title: 'Hello',
				fzdArr: [],
				imgArr: [],
				columns: ["BUTTERFLY(蝴蝶)", 'DHS(红双喜)'],
			}
		},
		components: {},
		async onLoad() {
			const {
				data: res
			} = await uni.$http.get('http://127.0.0.1:8848/comic/all')
			// console.log('查看请求的结果=>>', res.msg, res.data);
			this.imgArr = res.data
			console.log("ok!")
			// ------------------------
			const {
				data: res_2
			} = await uni.$http.get('http://127.0.0.1:8858/goods/all')
			// console.log('结果2=>>', res_2.data)
			this.fzdArr = res_2.data
		},
		methods: {
			showPopup() {
				this.show = true
			},

			onClose() {
				this.show = false
			},
			onConfirm(event) {
				const {
					// picker,
					value,
					index
				} = event.detail;
				console.log(value, index)
				this.show = false
			},
			onCancel() {
				this.show = false
			},
			gotoDetali(id, name, goodsicon) {
				// console.log("go", id)
				//在起始页面跳转到test.vue页面并传递参数
				uni.navigateTo({
					url: `/pages/detali/detali?id=${id}&name=${name}&goodsicon=${goodsicon}`
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.imgs {
		height: 300rpx;
		width: 700rpx;
	}

	.sw {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.uni-bg-red {
		background-color: red;
	}

	.uni-bg-green {
		background-color: green;
	}

	.uni-bg-blue {
		background-color: aqua;
	}

	.uni-margin-wrap {
		overflow: hidden;
		box-sizing: border-box;
		width: 100%;
		// transform: translateY(0); // 关键属性
		line-height: 1rpx; // 可以简单调整圆点位置
		border-radius: 20px;
		width: 700rpx;
	}

	.swiper {

		border-radius: 25px;
		height: 300rpx;
	}

	.swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
	}

	// 2222
	.mainCss {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.fenlei {
		margin-top: 30px;
	}

	.all {
		display: flex;
		justify-content: center;
	}

	.img {
		padding: 10rpx;
		height: 320rpx;
		width: 320rpx;
		border-radius: 25px;
	}

	.goods {
		width: 95%;
		display: flex;
		flex-wrap: wrap;
		// justify-content:  space;
		justify-content: space-between;
		align-items: center;

		.title {
			margin-top: 20rpx;
			background-color: #e8e8e8;
			border-radius: 20rpx;
			// border: 1px solid black;
			text-align: center;
			// height: 430rpx;
			width: 350rpx;

		}
	}

	.GoodsText {
		padding: 20rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
</style>
